package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.util.Log
import android.view.View
import android.widget.DatePicker
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.bean.*
import com.cheyun.netsalev3.bean.basedata.Member
import com.cheyun.netsalev3.bean.basedata.MemberGroup2
import com.cheyun.netsalev3.repository.AddClueActivityRepository
import com.cheyun.netsalev3.repository.FilterActivityRepository
import com.cheyun.netsalev3.utils.CommonFunc
import com.cheyun.netsalev3.utils.MySharedPreferences
import com.cheyun.netsalev3.view.choosecar.ChooseCarActivity
import com.cheyun.netsalev3.view.mars.choosecar.MarsChooseCarActivity
import com.cheyun.netsalev3.widget.BaseDialog
import com.cheyun.netsalev3.widget.DatePickerFragment
import com.cheyunkeji.er.utils.ToastUtil
import java.io.Serializable
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap

class FilterActivityViewModel(var filterActivityRepository: FilterActivityRepository) : BaseViewModel(), BaseDialog.BaseDialogListener {

    var addClueActivityRepository = AddClueActivityRepository()

    var v: View? = null

    var hasFilter = false

    //搜索条件类型(1,分类   2，时间  3，成员  4，排序)
    var filterType = MutableLiveData<Int>()

    //分类项数据源
    var infotype = arrayOf<KeyValueParam>()

    var filterType1LeftDate = MutableLiveData<List<KeyValueParam>>()
    //分类选中项
    lateinit var filterType1Choosed: KeyValueParam
    //分类项右边数据列表（选中）
    var filterType1RgihtList = MutableLiveData<List<DialogParam>>()
    //分类项选中的类型
    var filterType1Type = MutableLiveData<Int>()

    //时间选中项
    lateinit var filterType2Choosed: KeyValueParam

    var keyword = MutableLiveData<String>()
//    var keyword = ""

    var carBrandParamData = MutableLiveData<CarBrandParam>()

    //分类选中的值
    var type1HashMap = HashMap<String, String>()
    var type1HashMapDesc = ArrayList<DialogParam>()
    var type1DialogList = ArrayList<DialogParam>()
    var dialogList = MutableLiveData<List<DialogParam>>()
    var type1HashMapDescLivData = MutableLiveData<List<DialogParam>>()
    //时间选中的值
    var type2HashMap = HashMap<String, String>()
    //用户选中的值
    var type3HashMap = HashMap<String, String>()
    //排序选中的值
    var type4HashMap = HashMap<String, String>()


    //时间数据源
    var filterType2LeftDate = MutableLiveData<List<KeyValueParam>>()
    //开始时间，结束时间
    var startTime = ObservableField<String>("")
    var endTime = ObservableField<String>("")

    //成员显示列表
    var filterType3Type = MutableLiveData<Int>()
    var filterType3MemberDate = MutableLiveData<List<Member>>()
    var filterType3MemberGroupDate = MutableLiveData<List<MemberGroup2>>()
    var filterType3Owner = MutableLiveData<Int>()
    var filterType3Member = MutableLiveData<Int>()
    var filterType3MemberGroup = MutableLiveData<Int>()

    var owneruid = MutableLiveData<Int>()
    //排序
    var filterType4Sort = MutableLiveData<Int>()
    //排序数据源
    var filterType4Date = MutableLiveData<List<KeyValueParam>>()
    var filterType4Choosed = MutableLiveData<KeyValueParam>()
    var filterType4ChoosedValue: KeyValueParam? = null

    var filtersDialog: BaseDialog? = null



//    fun getFollowStatus(){
//        var moth: (f: Followstate) -> Unit = {
//            it.followstate.forEach { d->  gengjingzhuangtailist.add(DialogParam(d.title, d.id.toString()))}
//
//            initFilter1()
//        }
//        var fail: () -> Unit = {
//
//        }
//        addClueActivityRepository.getFollowStatus("","",moth,fail)
//    }

    //初始当前搜索条件分类
    init {
        filterType.postValue(1)

//        getFollowStatus()
    }

    fun onFilter(view: View, type: Int) {
        if (type == filterType.value) {
            myFinish()
            return
        }
        filterType.postValue(type)
    }

    fun onCancel() {
        myFinish()
    }

    //=====================分类======================
    //初始分类项
    init {
        var baseData = MySharedPreferences.getBaseData()
        //业务类型
        var infotypelist = ArrayList<DialogParam>()
        baseData?.infotype?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                infotypelist.add(item)
            }
        }
        //信息渠道
        var infoplacelist = ArrayList<DialogParam>()
        baseData?.infoplace?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                infoplacelist.add(item)
            }
        }
        //信息来源
        var infosourcelist = ArrayList<DialogParam>()
        baseData?.infosource?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                infosourcelist.add(item)
            }
        }

        //有效性判断
        var effectivelist = ArrayList<DialogParam>()
        baseData?.effective?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                effectivelist.add(item)
            }
        }
        //是否到店
        var licenceplatelist = arrayListOf(
                DialogParam("是", "1"),
                DialogParam("否", "0")
        )

        //信息来源
        var owneruidlist = ArrayList<DialogParam>()
        baseData?.member?.apply {
            for (i in this) {
                var item = DialogParam(i.realname, i.uid.toString())
                owneruidlist.add(item)
            }
        }
        //跟进状态
        var gengjingzhuangtailist = arrayListOf<DialogParam>()
        baseData?.followstate?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                gengjingzhuangtailist.add(item)
            }
        }

        //跟进级别
        var customerlevellist = ArrayList<DialogParam>()
        baseData?.customerlevel?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                customerlevellist.add(item)
            }
        }

        //跟进/回访方式
        var connectwaylist = ArrayList<DialogParam>()
        baseData?.connectway?.apply {
            for (i in this) {
                var item = DialogParam(i.title, i.id.toString())
                connectwaylist.add(item)
            }
        }

        infotype = arrayOf(
                //type2输入框类型 1选择类型框
                KeyValueParam("客户姓名", 2, "uname"),
                KeyValueParam("客户电话", 2, "phone"),
                KeyValueParam("首选车", 1, "series"),
                KeyValueParam("业务类型", infotypelist, "infotype"),
                KeyValueParam("信息渠道", infoplacelist, "infoplace"),
                KeyValueParam("信息来源", infosourcelist, "infosource"),
                KeyValueParam("有效性判断", effectivelist, "effective"),
                KeyValueParam("跟进状态", gengjingzhuangtailist, "followstate"),
                KeyValueParam("意向等级", customerlevellist, "customerlevel"),
                KeyValueParam("到店状态", connectwaylist, "customerlevel"),
                KeyValueParam("是否到店", licenceplatelist, "arrive")

        )
        infotype.forEach { it.IsSelect = false }
        filterType1LeftDate.postValue(infotype.toList())

        onChooseFilterType1(null, infotype.get(0))
    }

    fun onLookFilters(view: View) {
        if (type1HashMapDesc.size == 0) return
        var content = view.context
        if (content is AppCompatActivity) {
            filtersDialog = BaseDialog()
            filtersDialog?.listener = this
            filtersDialog?.show(content.supportFragmentManager, "missiles")
        }
    }

    fun onSubmit(view: View) {
        v = view
        searchFilter()
    }

    fun onChooseFilterType1(view: View?, item: KeyValueParam) {
        infotype.forEach { it.IsSelect = false }
        item.IsSelect = true
        filterType1Choosed = item
        //设置选中的类型
        filterType1Type.postValue(item.type)
        //设置选中列表数据
        if (item.type == 2) {
            if (type1HashMap.containsKey(item.idname)) {
                keyword.postValue(type1HashMap.get(item.idname)!!)
            } else {
                keyword.postValue("")
            }
        } else if (item.type == 5) {
            if (type1HashMap.containsKey(item.idname)) {
                var v = type1HashMap.get(item.idname)
                item.poplistdata.forEach {
                    if (it.id.equals(v)) {
                        it.IsSelect = true
                    }
                }
            } else {
                item.poplistdata.forEach {
                    it.IsSelect = false
                }
            }
        }
        filterType1RgihtList.postValue(item.poplistdata)
        //选中类型为1时，跳转到不同页面进行选择
        if (item.type == 1) {
            if (item.idname.equals("series")) {
                //拟购车系
                onClicCar(view!!, 1)
            } else if (item.idname.equals("pbrand")) {
                //现用品牌
                onClicCar2(view!!, 0)
            } else if (item.idname.equals("iseries")) {
                //订车车系
                onClicCar3(view!!, 0, 103)
            } else if (item.idname.equals("dseries")) {
                //提车车系
                onClicCar3(view!!, 0, 104)
            }
        }
    }

    fun onClickFilterType1Btn() {
//        if(keyword.isEmpty())return
        if (keyword.value!!.isEmpty()) return
//        addType1HasMap(filterType1Choosed.idname,keyword.value!!)
        addType1HasMap(filterType1Choosed, keyword.value!!, keyword.value!!)
    }

    fun onChooseFilterType1Value(item: DialogParam) {
        filterType1Choosed.poplistdata.forEach {
            it.IsSelect = false
            if (it.id == item.id) {
                it.IsSelect = true

                addType1HasMap(filterType1Choosed, it.id, item)
            }
//            addType1HasMap(filterType1Choosed.idname,it.id)

        }
        filterType1RgihtList.postValue(filterType1Choosed.poplistdata)
    }

    //    fun addType1HasMap(key:String,value:String){
//        if(type1HashMap.containsKey(key)){
//            type1HashMap[key] = value
//        }else{
//            type1HashMap.put(key,value)
//        }
//        Log.d("Filter","选中值!!!!!!!!!!!!!!!!!!")
//        type1HashMap.forEach{
//            Log.d("Filter",it.key+":"+it.value)
//        }
//    }
    fun addType1HasMap(choose: KeyValueParam, value: String, desc: Any? = null) {
        if (type1HashMap.containsKey(choose.idname)) {
            type1HashMap[choose.idname] = value
        } else {
            type1HashMap.put(choose.idname, value)
        }
//        if(type1HashMapDesc.containsKey(choose.idname)){
//            type1HashMapDesc[choose.idname] = desc!!
//        }else{
//            type1HashMapDesc.put(choose.idname,desc!!)
//        }

//        type1HashMapDescLivData.postValue(type1HashMapDesc)

        var same = type1HashMapDesc.find { it.ikey.equals(choose.idname) }
        if (same != null) {
            type1HashMapDesc.remove(same)
            type1DialogList.remove(same)
        }

        var v = ""
        if (desc is CarBrandParam) {
            v = desc.brandname + " " + desc.seriesname + " " + desc.specname
        } else if (desc is DialogParam) {
            v = desc.name
        } else {
            v = desc as String
        }
        var dialogParam = DialogParam(choose.key, v)
        dialogParam.ikey = choose.idname

        type1HashMapDesc.add(dialogParam)
        type1DialogList.add(dialogParam)
        type1HashMapDescLivData.postValue(type1HashMapDesc)
        dialogList.postValue(type1DialogList)

        Log.d("Filter", "选中值!!!!!!!!!!!!!!!!!!")
        type1HashMap.forEach {
            Log.d("Filter", it.key + ":" + it.value)
        }
    }


    /**
     * 点击 品牌=0 车系=1车型=2
     */
    fun onClicCar(view: View, p: Int) {
        var content = view.context
        if (content is AppCompatActivity) {
            var intent = Intent(view.context, MarsChooseCarActivity::class.java)
            intent.putExtra("pos", p)
            intent.putExtra("Isspec",true)
            var car = CarBrandParam();
            intent.putExtra("car", car as Serializable)
            content.startActivityForResult(intent, 101)
        }
    }

    /**
     * 点击 现有品牌=0 车系=1
     */
    fun onClicCar2(view: View, p: Int) {
        var content = view.context
        if (content is AppCompatActivity) {
            var intent = Intent(view.context, ChooseCarActivity::class.java)
            intent.putExtra("pos", p)
            intent.putExtra("Isbrand", true)
            var car = CarBrandParam()
            intent.putExtra("car", car as Serializable)
            content.startActivityForResult(intent, 102)
        }
    }
//
    /**
     * 订车车系
     */
    fun onClicCar3(view: View, p: Int, type: Int) {
        var content = view.context
        if (content is AppCompatActivity) {
            var intent = Intent(view.context, ChooseCarActivity::class.java)
            intent.putExtra("pos", p)
            intent.putExtra("Isseries", true)
            var car = CarBrandParam()
            intent.putExtra("car", car as Serializable)
            content.startActivityForResult(intent, type)
        }
    }

    fun setCarData(carBrandParam: CarBrandParam) {
//        addType1HasMap(filterType1Choosed.idname,carBrandParam.series)
        addType1HasMap(filterType1Choosed, carBrandParam.series, carBrandParam)
        carBrandParamData.postValue(carBrandParam)
    }

    fun setCarData2(carBrandParam: CarBrandParam) {
//        addType1HasMap(filterType1Choosed.idname,carBrandParam.brand)
        addType1HasMap(filterType1Choosed, carBrandParam.brand, carBrandParam)
        carBrandParamData.postValue(carBrandParam)
    }
    //=====================分类======================


    //=====================时间======================
    var today_3 = ""
    var today_2 = ""
    var today_1 = ""

    var datetypelist = arrayListOf(
            KeyValueParam("下次沟通时间", 2, "remindetime"),
            KeyValueParam("建档时间", 2, "dateline"),
            KeyValueParam("最后跟进时间", 2, "followtime")
    )

    //初始时间
    init {
        datetypelist.forEach { it.IsSelect = false }
        filterType2LeftDate.postValue(datetypelist.toList())
        today_3 = "前天(" + CommonFunc.getWeekOfDate(CommonFunc.getPastDate2(2)) + ")"
        today_2 = "昨天(" + CommonFunc.getWeekOfDate(CommonFunc.getPastDate2(1)) + ")"
        today_1 = "今天(" + CommonFunc.getWeekOfDate(Date()) + ")"

//        onChooseFilterType2(null,datetypelist.get(0))
    }

    fun onChooseFilterType2(view: View?, item: KeyValueParam) {
        datetypelist.forEach { it.IsSelect = false }
        item.IsSelect = true
        filterType2Choosed = item
        startTime.set("")
        endTime.set("")
    }

    fun onChooseDateType(view: View, type: Int) {
        if (type >= 0) {
            var time = CommonFunc.getPastDate(type)
            startTime.set(time)
            endTime.set(time)
        } else if (type == -1) {
            var content = view.context
            if (content is AppCompatActivity) {
                val datePickerFragment = DatePickerFragment()
                datePickerFragment.clickOk = this::onDateSetstart
                datePickerFragment.show(content.supportFragmentManager, "datePicker")
            }
        } else if (type == -2) {
            var content = view.context
            if (content is AppCompatActivity) {
                val datePickerFragment = DatePickerFragment()
                datePickerFragment.clickOk = this::onDateSetend
                datePickerFragment.show(content.supportFragmentManager, "datePicker")
            }
        }
    }

    /**
     * 开始时间回调
     */
    fun onDateSetstart(view: DatePicker, year: Int, month: Int, day: Int) {
        startTime.set("$year-$month-$day")
    }

    /**
     * 结束时间回调
     */
    fun onDateSetend(view: DatePicker, year: Int, month: Int, day: Int) {
        endTime.set("$year-$month-$day")
    }

    fun onDateSubmit(view: View) {
        v = view

        type2HashMap.clear()

        if (startTime.get()!!.isEmpty() && endTime.get()!!.isEmpty()) {
            ToastUtil.toastShortMessage("请选择要查找的开始时间、结束时间")
            return
        }
        type2HashMap.put("datetype", filterType2Choosed.idname)
        type2HashMap.put("stime", startTime.get()!!)
        type2HashMap.put("etime", endTime.get()!!)

        searchFilter()
    }
    //=====================时间======================

    //=====================成员======================
    var member: ArrayList<Member> = ArrayList()
    var memberGroup: ArrayList<MemberGroup2> = ArrayList()

    init {
        filterType3Type.postValue(1)
        var memberList = MySharedPreferences.getBaseData()?.member
        var dealerId = MySharedPreferences.getLoginData()?.member?.dealerid!!
        var check = false
        if (MySharedPreferences.getLoginData()?.channel?.isgroup.equals("1") && MySharedPreferences.getLoginData()?.member?.dealerid != 0) {
            check = true
        }
        memberList?.apply {
            for (it in this) {
                if (check) {
                    if (it.dealerid == dealerId) {
                        member.add(it)
                    }
                } else {
                    member.add(it)
                }
            }
        }
        filterType3MemberDate.postValue(member)
        filterType3Owner.postValue(-1)

    }

    fun onChangeFilter3Type(type: Int) {
        filterType3Type.postValue(type)
        if (type == 2) {
            if (memberGroup.size == 0) {
                filterActivityRepository.getMemberGroup(this::setMemberGroupList)
            }
        }
    }

    private fun setMemberGroupList(list: ArrayList<MemberGroup2>) {
        memberGroup = list
        filterType3MemberGroupDate.postValue(list)
    }

    fun onChooseFilterType3Value(view: View, member: Int) {
        v = view

        filterType3Owner.postValue(member)

        if (member == 1) {
            type3HashMap.put("owneruid", MySharedPreferences.getLoginData()?.member?.uid.toString())
        } else {
            type3HashMap.clear()
        }
        searchFilter()
    }

    fun onChooseFilterType3Member(view: View?, item: Member) {
        v = view

        type3HashMap.clear()
        type3HashMap.put("owneruid", item.uid.toString())

        searchFilter()

        owneruid.postValue(item.uid)
    }

    fun onChooseFilterType3MemberGroup(view: View, item: MemberGroup2) {
        v = view

        type3HashMap.clear()
        type3HashMap.put("groupid", item.id.toString())

        searchFilter()
    }

    fun searchMember(view: View, txt: String) {
        if (filterType3Type.value == 1) {
            var list: ArrayList<Member> = ArrayList()
            member.forEach {
                if (it.realname.contains(txt)) {
                    list.add(it)
                }
            }
            filterType3MemberDate.postValue(list)
        } else {
            var list: ArrayList<MemberGroup2> = ArrayList()
            memberGroup.forEach {
                if (it.title.contains(txt)) {
                    list.add(it)
                }
            }
            filterType3MemberGroupDate.postValue(list)
        }
    }
    //=====================成员======================

    //=====================排序======================
    var sortlist = arrayListOf(
            KeyValueParam("级别", 2, "customerlevel"),
            KeyValueParam("电话号码", 2, "phone"),
            KeyValueParam("业务类型", 2, "infotypename"),
            KeyValueParam("信息渠道", 2, "infoplacename"),
            KeyValueParam("信息来源", 2, "infosourcename"),
            KeyValueParam("线索拥有者", 2, "ownername"),
            KeyValueParam("最后跟进时间", 2, "followtime"),
            KeyValueParam("下次跟进时间", 2, "remindetime"),
            KeyValueParam("是否到店", 2, "arrive"),
            KeyValueParam("是否试驾", 2, "driving"),
            KeyValueParam("跟进报警", 2, "followalarm"),
            KeyValueParam("提交时间", 2, "posttime"),
            KeyValueParam("拟购车系", 2, "seriesname"),
            KeyValueParam("拟购车型", 2, "specname"),
            KeyValueParam("拟购时间", 2, "ibuytimename"),
            KeyValueParam("性别", 2, "sex"),
            KeyValueParam("号码归属地", 2, "phoneaddr"),
            KeyValueParam("省份", 2, "provincename"),
            KeyValueParam("城市", 2, "cityname"),
            KeyValueParam("地区", 2, "districtname"),
            KeyValueParam("订单签约时间", 2, "endtime"),
            KeyValueParam("提车时间", 2, "delivertime"),
            KeyValueParam("建档时间", 2, "dateline"),
            KeyValueParam("客户编号", 2, "iorderid")
    )

    init {
        initType4()
    }

    fun initType4() {
        type4HashMap.clear()
        sortlist.forEach { it.IsSelect = false }
        filterType4Sort.postValue(1)
        filterType4Date.postValue(sortlist)
    }

    fun onChooseFilterType4Sort(sort: Int) {
        filterType4Sort.postValue(sort)
    }

    fun onChooseFilterType4Value(view: View, item: KeyValueParam) {
        sortlist.forEach { it.IsSelect = false }
        item.IsSelect = true
        filterType4ChoosedValue = item
        filterType4Choosed.postValue(item)
    }

    fun onSortSubmit(view: View) {
        v = view
        type4HashMap.clear()

        if (filterType4ChoosedValue != null) {
            type4HashMap.put("sort", filterType4ChoosedValue?.idname!!)
            type4HashMap.put("order", if (filterType4Sort.value == 1) "desc" else "asc")
        }

        searchFilter()
    }
    //=====================排序======================


    fun onClearFilter(view: View, type: Int) {
        v = view
        if (type == 1) {
            type1HashMap.clear()
            infotype.forEach { it.IsSelect = false }
            filterType1LeftDate.postValue(infotype.toList())

            onChooseFilterType1(null, infotype.get(0))

            searchFilter()

        } else if (type == 2) {
            type2HashMap.clear()
            datetypelist.forEach { it.IsSelect = false }
            filterType2LeftDate.postValue(datetypelist.toList())
            startTime.set("")
            endTime.set("")
            onChooseFilterType2(null, datetypelist.get(0))

            searchFilter()

        } else if (type == 4) {
            initType4()
            filterType4ChoosedValue = null

            searchFilter()
        }
    }

    fun searchFilter() {
        var filters = HashMap<String, String>()
        if (type1HashMap.size > 0)
            filters.putAll(type1HashMap)
        if (type2HashMap.size > 0)
            filters.putAll(type2HashMap)
        if (type3HashMap.size > 0)
            filters.putAll(type3HashMap)
        if (type4HashMap.size > 0)
            filters.putAll(type4HashMap)

        Log.d("要查询的条件", "========================================")
        filters.forEach {
            Log.d("要查询的条件", it.key + ":" + it.value)
        }
        Log.d("要查询的条件", "========================================")

        if (filters.size == 0 && !hasFilter) {
            myFinish()
        } else {
            var context = v?.context
            if (context is AppCompatActivity) {
                var intent = Intent()
                intent.putExtra("type1Data", type1HashMap as Serializable)
                intent.putExtra("type1DataDesc", type1HashMapDesc as Serializable)
                intent.putExtra("type2Data", type2HashMap as Serializable)
                intent.putExtra("type3Data", type3HashMap as Serializable)
                intent.putExtra("type4Data", type4HashMap as Serializable)
                context.setResult(102, intent)
                context.finish()
            }
        }
    }

    fun setInitFilter(type1Data: HashMap<String, String>, type1DataDesc: ArrayList<DialogParam>, type2Data: HashMap<String, String>,
                      type3Data: HashMap<String, String>, type4Data: HashMap<String, String>) {
        if (type1Data.size > 0 || type2Data.size > 0 || type3Data.size > 0 || type4Data.size > 0) {
            hasFilter = true
        }
        type1HashMap = type1Data
        type1HashMapDesc = type1DataDesc
        type2HashMap = type2Data
        type3HashMap = type3Data
        type4HashMap = type4Data
        type1HashMapDescLivData.postValue(type1HashMapDesc)
        type1DataDesc.forEach {
            type1DialogList.add(it)
        }
        dialogList.postValue(type1DialogList)


        //初始回填分类
        onChooseFilterType1(null, infotype.get(0))

        //初始回填时间
        if (type2Data != null && type2Data.size > 0) {
            var datetype = type2Data.get("datetype")
            datetypelist.forEach {
                it.IsSelect = false
                if (it.idname.equals(datetype)) {
                    it.IsSelect = true
                    filterType2Choosed = it
                }
            }
            filterType2LeftDate.postValue(datetypelist)
            if (type2Data.containsKey("stime")) {
                startTime.set(type2Data.get("stime"))
            }
            if (type2Data.containsKey("etime")) {
                endTime.set(type2Data.get("etime"))
            }
        } else {
            onChooseFilterType2(null, datetypelist.get(0))
        }

        //初始回填成员
        if (type3Data != null && type3Data.size > 0) {
            if (type3Data.containsKey("owneruid")) {
                var owneruid = type3Data.get("owneruid")
                var uid = MySharedPreferences.getLoginData()?.member?.uid.toString()
                if (owneruid.equals(uid)) {
                    filterType3Owner.postValue(1)
                } else {

                }
            } else {
                if (type3Data.containsKey("groupid")) {
                    var groupid = type3Data.get("groupid")

                }
            }
        }

        //初始回填排序
        if (type4Data != null && type4Data.size > 0) {
            filterType4Sort.postValue(if (type4Data.get("order").equals("desc")) 1 else 0)
            var sort = type4Data.get("sort")
            sortlist.forEach {
                if (it.idname.equals(sort)) {
                    it.IsSelect = true
                    filterType4ChoosedValue = it
                    filterType4Choosed.postValue(it)
                }
            }
            filterType4Date.postValue(sortlist)
        }
    }

    /**弹窗相关**/


    override var title: String = "已选择"

    override var content: String? = null
    override var layoutId: Int = R.layout.base_dialog_list_delete_item


    override var list: MutableLiveData<List<*>>
        get() {
            return dialogList as MutableLiveData<List<*>>
        }
        set(value) {
            list = value
        }

    override fun onClickCancel(view: View) {
    }

    override fun onClickOk(view: View) {
        type1HashMapDesc.forEach {
            if (!type1DialogList.contains(it)) {
                type1HashMap.remove(it.ikey)
            }
        }
        type1HashMapDesc.clear()
        type1DialogList.forEach {
            type1HashMapDesc.add(it)
        }

        type1HashMapDescLivData.postValue(type1HashMapDesc)
    }

    override fun onClickItem(view: View, param: Any) {
        var d = param as DialogParam
        type1DialogList.remove(d)
        dialogList.postValue(type1DialogList)
    }
    /**弹窗相关**/
}
